<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="app">
    <my-table :data="teachers">
      <template #header>
        <th>姓名</th>
        <th>性别</th>
        <th>工资</th>
        <th>教龄</th>
      </template>
      <template #td="{ item }">
        <td>{{item.name}}</td>
        <td>{{item.gender}}</td>
        <td>{{item.salary}}</td>
        <td>{{item.age}}</td>
      </template>
    </my-table>
  </div>

  <script>
    let component = {
      props: {
        data: {
          type: Array,
          required: true
        }
      },
      data() {
        return {}
      },
      template: `
        <table>
          <thead>
            <tr>
              <slot name="header"></slot>
            </tr>
          </thead>  
          <tbody>
            <tr v-for="(item, index) in data">
              <slot name="td" :item="item"></slot>
            </tr>
          </tbody>
        </table>
      `
    }
    let vm = new Vue({
      el: "#app",
      data: {
        teachers: [
          { name: '李老师', gender: 'male', salary: '5000', age: '35' },
          { name: '王老师', gender: 'female', salary: '6000', age: '38' },
          { name: '张老师', gender: 'male', salary: '7000', age: '42' },
        ],
        students: [
          { name: '张三', gender: 'male', grade: '350' },
          { name: '李四', gender: 'female', grade: '380' },
          { name: '王五', gender: 'male', grade: '420' },
        ]
      },
      methods: {

      },
      created() {

      },
      components: {
        myTable: component
      }
    })
  </script>
</body>

</html>